package cn.wzx.service;

import cn.wzx.entity.BookType;
import cn.wzx.mapper.BookTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BookTypeServiceImpl implements BookTypeService {

    @Autowired(required = false)
    BookTypeMapper bookTypeMapper;

    @Override
    // 书本类型全查询
    public List<BookType> findAll() {
        return bookTypeMapper.findAll();
    }

    @Override
    // 根据ID查询书本类型
    public BookType findById(Integer id) {
        return bookTypeMapper.findById(id);
    }

    @Override
    // 添加类型
    public void add(Integer id,String type) {
        Map map = new HashMap();
        map.put("id",id);
        map.put("type",type);
        // 如果id==0则进行添加操作，id>0则进行修改操作
        if (id==0){
            bookTypeMapper.add(type);
        }
        if (id>0){
            bookTypeMapper.update(map);
        }

    }

}
